<%--
  Created by IntelliJ IDEA.
  User: caojian
  Date: 2017/3/10
  Time: 下午5:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="xmb" uri="http://xmb.suishoupai.com/tags" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>认证列表</title>
    <jsp:include page="common/common_css.jsp"/>
</head>
<body>
<jsp:include page="common/header.jsp"/>
<div class="ui main container">
    <jsp:include page="common/message.jsp"/>
    <table class="ui celled padded table">
        <thead>
        <tr>
            <th class="center aligned">email</th>
            <th class="center aligned">类型</th>
            <th class="center aligned">时间</th>
            <th class="center aligned">操作</th>
        </tr>
        </thead>
        <tbody>
        <c:choose>
            <c:when test="${fn:length(auths.list) > 0}">
                <c:forEach items="${auths.list}" var="auth">
                    <tr data-email="${auth.email}" data-type="${auth.type}">
                        <td class="center aligned">${auth.email}</td>
                        <td class="center aligned">
                            <c:choose>
                                <c:when test="${auth.type==1}">
                                    账号激活
                                </c:when>
                                <c:when test="${auth.type==2}">
                                    忘记密码
                                </c:when>
                                <c:otherwise>
                                    不知道的type
                                </c:otherwise>
                            </c:choose>
                        </td>
                        <td class="center aligned"><xmb:formatDate value="${auth.updateTime}"/></td>
                        <td class="center aligned">
                            <c:if test="${auth.type==1}">
                                <button class="ui basic button JS-re">
                                    <i class="undo icon"></i>
                                    重发激活邮件
                                </button>
                            </c:if>
                        </td>
                    </tr>
                </c:forEach>
            </c:when>
            <c:otherwise>
                <tr>
                    <td class="center aligned" colspan="4">一条认证都没有。</td>
                </tr>
            </c:otherwise>
        </c:choose>
        </tbody>
        <tfoot>
        <tr>
            <th colspan="6" class="center aligned">
                <c:set var="pagination" scope="session" value="${auths}"/>
                <c:set var="paginationAction" scope="session" value="auth"/>
                <jsp:include page="common/page.jsp"/>
            </th>
        </tr>
        </tfoot>
    </table>
</div>
<!--确认弹窗-->
<div id="JS-modal-confirm" class="ui basic modal">
    <div class="content" style="text-align: center;">
        <div style="background-color: white;display: inline-block;padding: 20px 60px;border-radius: 5px;">
            <div id="JS-modal-confirm-title" style="display: inline-block;color: black;margin-bottom: 50px;">
            </div>
            <br>
            <div class="actions">
                <div class="ui small primary blue column approve button" style="display: inline-block;">
                    OK
                </div>
                <div class="ui small primary blue column cancel button"
                     style="display: inline-block;margin-left: 30px;">Cancel
                </div>
            </div>
        </div>
    </div>
</div>

<jsp:include page="common/footer.jsp"/>
<jsp:include page="common/common_js.jsp"/>
<script>
    $(function () {
        $('.JS-re').click(function () {
            var email = $(this).parent().parent().data("email");
            var type = $(this).parent().parent().data("type");
            $('#JS-modal-confirm-title').text("确定重发邮件'" + email + "'？");
            $('#JS-modal-confirm').modal({
                closable: false, allowMultiple: true, observeChanges: true,
                onApprove: function () {
                    if ($('#JS-modal-confirm .approve.button').hasClass('loading')) {
                        return false;
                    }
                    $('#JS-modal-confirm .approve.button').addClass('loading');
                    common.ajax({
                        url: ROOT + "/auth/re",
                        data: {
                            email: email,
                            type: type
                        },
                        type: 'post',
                        dataType: 'json',
                        success: function (data) {
                            alert("重发邮件成功！");
                            window.location.reload();
                        },
                        complete: function () {
                            $('#JS-modal-confirm .approve.button').removeClass('loading');
                        }
                    });
                    return false;
                },
                onDeny: function () {
                    return !$('#JS-modal-confirm .approve.button').hasClass('loading');
                }
            }).modal("show");
        });
    });
</script>
</body>
</html>
